// pages/home/home.js
const {Data} = require("../../utils/data")
Page({
  data: {

  },

  onLoad: async function (options) {
    var module = await import("../../utils/http");
    var hotRes = await module.Url.hotUrl();
    var japanRes = await module.Url.japanUrl();
    var djRes = await module.Url.djUrl();
    var hot = this.handleData(hotRes.data.playlists).slice(0,3);
    var japan = this.handleData(japanRes.data.playlists).slice(0,3);
    var dj = this.handleDjData(djRes.data.result).slice(0,3);
    this.setData({
      hot,
      japan,
      dj
    })
  },
  handleData(arr){
    var res = [];
    arr.forEach(item=>{
      var{id,name,coverImgUrl,playCount} = item;
      playCount = Data.HandlePlayCount(playCount);
      res.push({id,name,picUrl:coverImgUrl,playCount});
    })
    return res;
  },
  handleDjData(arr){
    arr.forEach(item=>{
      item.program.listenerCount = Data.HandlePlayCount(item.program.listenerCount)
    })
    return arr
  },
  toHot(event){
    var urltype = event.currentTarget.dataset.urltype;
    wx.navigateTo({
      url: `/pages/more/more?urltype=${urltype}`,
    })
  },
  toJapan(event){
    var urltype = event.currentTarget.dataset.urltype;
    wx.navigateTo({
      url: `/pages/more/more?urltype=${urltype}`,
    })
  },
  toDj(event){
    var urltype = event.currentTarget.dataset.urltype;
    wx.navigateTo({
      url: `/pages/more/more?urltype=${urltype}`,
    })
  },
  toAlbum(event){
    var id = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/album/album?id=${id}`,
    })
  }
})
